# -*- coding: utf-8 -*-
# @Time    : 2024/8/30 下午4:47
# @Author  : liujun
# @Email   : 2592730854@qq.com
# @File    : knowledge_page.py
# @Software: PyCharm


from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select

class  KnowledgePage(BasePage):
    """知识页面"""
    url="/crm/index.php?m=knowledge"

    knowledge_add_locator = (By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(2) > div > div.pull-right > a")  # 添加知识
    # 全部

    all_locator = (
        By.CSS_SELECTOR, "body > div.container > div.row > div.span2.knowledgecate > ul > li:nth-child(2) > a")
    # 第一个类别
    one_sort_locator = (
        By.CSS_SELECTOR, "body > div.container > div.row > div.span2.knowledgecate > ul > li:nth-child(3) > a")
    # 第二个类别
    two_sort_locator = (
        By.CSS_SELECTOR, "body > div.container > div.row > div.span2.knowledgecate > ul > li:nth-child(4) > a")
    # 第三个类别
    third_sort_locator = (
        By.CSS_SELECTOR, "body > div.container > div.row > div.span2.knowledgecate > ul > li:nth-child(5) > a")

    condition_one_select_locator = (By.ID, "field")  # 第一个筛选框
    condition_two_select_locator = (By.ID, "condition")  # 第二个筛选框
    search_locator = (By.ID, "search")  # 搜索框
    search_btn_locator = (By.ID, "dosearch")  # 搜索按钮

    check_box_locator = (By.NAME, "knowledge_id[]")  # 勾选框
    delete_locator = (By.ID, "delete")  # 删除

    # 知识工具
    knowledge_tool_locator = (
    By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(2) > div > div.pull-right > div > button")
    knowledge_import_locator = (By.ID, "import_excel")  # 导入知识
    # 点击导入
    import_btn_locator = (By.CSS_SELECTOR,
                          "#dialog-import > form > table > tbody > tr:nth-child(4) > td:nth-child(2) > input.btn.btn-primary")




    def click_knowledge_add(self):
        """点击添加知识"""
        self.driver.find_element(*self.knowledge_add_locator).click()

    # 点击第全部类别
    def click_all(self):
        self.driver.find_element(*self.all_locator).click()
    # 点击第一个类别
    def click_one_sort(self):
        self.driver.find_element(*self.one_sort_locator).click()

    # 点击第二个类别
    def click_two_sort(self):
        self.driver.find_element(*self.two_sort_locator).click()

    # 点击第三个类别
    def click_third_sort(self):
        self.driver.find_element(*self.third_sort_locator).click()

    def select_condition_one(self,choose_one):
       """第一个筛选框"""
       condition_one_select_element = self.driver.find_element(*self.condition_one_select_locator)
       condition_one_select_obj = Select(condition_one_select_element)
       condition_one_select_obj.select_by_visible_text(choose_one)

    def select_condition_two(self,choose_two):
        """第二个筛选框"""
        condition_two_select_element = self.driver.find_element(*self.condition_two_select_locator)
        condition_two_select_obj = Select(condition_two_select_element)
        condition_two_select_obj.select_by_visible_text(choose_two)

    def input_search_select(self,name):
        """搜索框输入关键字"""
        self.driver.find_element(*self.search_locator).send_keys(name)
    def click_search_btn(self):
        """点击搜索按钮"""
        self.driver.find_element(*self.search_btn_locator).click()

    def click_check_box(self):
        """勾选一条知识"""
        self.driver.find_element(*self.check_box_locator).click()
    def click_delete(self):
        """点击删除"""
        self.driver.find_element(*self.delete_locator).click()

    def accept(self):
        """确定警告框"""
        self.driver.switch_to.alert.accept()

    def click_knowledge_tool(self):
        """点击知识工具"""
        self.driver.find_element(*self.knowledge_tool_locator).click()
    def click_knowledge_import(self):
        """点击导入知识"""
        self.driver.find_element(*self.knowledge_import_locator).click()
    def upload_file(self,file):
       """上传文件"""
       self.driver.find_element(By.NAME, "excel").send_keys(file)

    def click_import_btn(self):
        """点击导入"""
        self.driver.find_element(*self.import_btn_locator).click()








